package com.bhs.sansonglogistics.ui.order;

import static com.google.android.material.tabs.TabLayout.MODE_SCROLLABLE;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.base.BaseFragment;
import com.bhs.sansonglogistics.bean.TabBean;
import com.bhs.sansonglogistics.ui.home.FragmentAdapter;
import com.bhs.sansonglogistics.ui.home.OrderGoodsListFragment;
import com.bhs.sansonglogistics.view.SelectedFont;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

/**
 * 上游来货订单
 */
public class  UpstreamShipmentOrderFragment extends BaseFragment {

    private TabLayout tabLayout;
    private ViewPager2 viewPage;
    private List<TabBean> tabBeanList=new ArrayList<>();
    public static UpstreamShipmentOrderFragment newInstance() {
        return new UpstreamShipmentOrderFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    public int initLayout() {
        return R.layout.fragment_upstream_shipment_order;
    }

    @Override
    public void initView(View root) {
        tabLayout = view.findViewById(R.id.tabLayout);
        viewPage = view.findViewById(R.id.view_page);
        tabBeanList.add(new TabBean("待派送","1"));
        tabBeanList.add(new TabBean("待自提","2"));
        tabBeanList.add(new TabBean("到付","3"));
        tabBeanList.add(new TabBean("有回单","4"));
        tabBeanList.add(new TabBean("已完成","5"));
    }

    @Override
    public void initData() {
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        //tab切换时候的字体设置
        tabLayout.addOnTabSelectedListener(new SelectedFont(activity));
        ArrayList<BaseFragment> fragments = new ArrayList<>();
        for (TabBean tabBean : tabBeanList) {
            fragments.add(OrderGoodsListFragment.newInstance(tabBean.getType(),3));
        }
        viewPage.setOffscreenPageLimit(fragments.size());
        viewPage.setAdapter(new FragmentAdapter(activity, fragments));
        new TabLayoutMediator(tabLayout, viewPage, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(tabBeanList.get(position).getTypeName());
            }
        }).attach();
    }

}